package com.yunchao.feature.lock.presentation.screen

import android.os.Bundle
import android.view.View
import by.kirich1409.viewbindingdelegate.viewBinding
import com.xuexiang.xui.utils.WidgetUtils
import com.yunchao.feature.base.presentation.activity.BaseFragment
import com.yunchao.feature.lock.R
import com.yunchao.feature.lock.databinding.FragmentLockLogisticsBinding
import com.yunchao.feature.lock.domain.model.LockInfoModel
import com.yunchao.feature.lock.presentation.adapter.LockLogAdapter

internal class LockLogisticsFragment : LockFragment(R.layout.fragment_lock_logistics) {

    private val binding: FragmentLockLogisticsBinding by viewBinding<FragmentLockLogisticsBinding>()

    private val lockLogAdapter: LockLogAdapter by lazy { LockLogAdapter() }

    override fun initView(view: View, savedInstanceState: Bundle?) {
        binding.lockLogisticsRecyclerView.apply {
            adapter = lockLogAdapter
            WidgetUtils.initRecyclerView(this, 0)
        }
    }

    override fun handlePageSuccess(lockInfoModel: LockInfoModel) {
        super.handlePageSuccess(lockInfoModel)
        lockLogAdapter.submitList(lockInfoModel.lockLogList)
        binding.lockNumber.text = getString(
            com.yunchao.feature.base.R.string.锁号STR,
            lockInfoModel.lockEPCInfo.id
        )
        binding.lockEpcContent.text =
            getString(com.yunchao.feature.base.R.string.EPCSTR, lockInfoModel.lockEPCInfo.epc)

        binding.lockLogisticsNum.text =
            getString(
                com.yunchao.feature.base.R.string.物流日志总数STR2,
                lockInfoModel.lockLogisticsCount
            )
    }

    override fun handlePageIdle() {
        binding.lockNumber.setText(com.yunchao.feature.base.R.string.锁号)
        binding.lockEpcContent.setText(com.yunchao.feature.base.R.string.EPC)
        binding.lockLogisticsNum.setText(com.yunchao.feature.base.R.string.物流日志总数)
    }

    override fun onceScanLock() {
        viewModel.readLockLogistics()
    }
}